package com.ruoyi.web.controller.gas;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.gas.domain.GasEventDict;
import com.ruoyi.gas.service.IGasEventDictService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 事件类型字典Controller
 *
 * @author ruoyi
 * @date 2023-12-11
 */
@RestController
@RequestMapping("/gas/eventDict")
public class GasEventDictController extends BaseController
{
    @Autowired
    private IGasEventDictService gasEventDictService;

    /**
     * 查询事件类型字典列表
     */
    @PreAuthorize("@ss.hasPermi('gas:eventDict:list')")
    @GetMapping("/list")
    public TableDataInfo list(GasEventDict gasEventDict)
    {
        startPage();
        List<GasEventDict> list = gasEventDictService.selectGasEventDictList(gasEventDict);
        return getDataTable(list);
    }

    /**
     * 导出事件类型字典列表
     */
    @PreAuthorize("@ss.hasPermi('gas:eventDict:export')")
    @Log(title = "事件类型字典", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, GasEventDict gasEventDict)
    {
        List<GasEventDict> list = gasEventDictService.selectGasEventDictList(gasEventDict);
        ExcelUtil<GasEventDict> util = new ExcelUtil<GasEventDict>(GasEventDict.class);
        util.exportExcel(response, list, "事件类型字典数据");
    }

    /**
     * 获取事件类型字典详细信息
     */
//    @PreAuthorize("@ss.hasPermi('gas:eventDict:query')")
    @GetMapping(value = "/{code}")
    public AjaxResult getInfo(@PathVariable("code") Long code)
    {
        return success(gasEventDictService.selectGasEventDictByCode(code));
    }

    /**
     * 新增事件类型字典
     */
    @PreAuthorize("@ss.hasPermi('gas:eventDict:add')")
    @Log(title = "事件类型字典", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody GasEventDict gasEventDict)
    {
        return toAjax(gasEventDictService.insertGasEventDict(gasEventDict));
    }

    /**
     * 修改事件类型字典
     */
    @PreAuthorize("@ss.hasPermi('gas:eventDict:edit')")
    @Log(title = "事件类型字典", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody GasEventDict gasEventDict)
    {
        return toAjax(gasEventDictService.updateGasEventDict(gasEventDict));
    }

    /**
     * 删除事件类型字典
     */
    @PreAuthorize("@ss.hasPermi('gas:eventDict:remove')")
    @Log(title = "事件类型字典", businessType = BusinessType.DELETE)
	@DeleteMapping("/{codes}")
    public AjaxResult remove(@PathVariable Long[] codes)
    {
        return toAjax(gasEventDictService.deleteGasEventDictByCodes(codes));
    }
}
